/*****************************************************************//**
 * \file   Camera.cpp
 * \brief  该文件主要处理摄像头开关及数据处理相关代码
 * 
 * \author Administrator
 * \date   July 2021
 * \modify by Administrator
 * \date   July 2021

 *********************************************************************/
#include "Camera.h"
#include <opencv2/video.hpp>

int Camera::iCameraCount = 0;
cv::VideoCapture capture(0);//视频流捕获器
/**
 * \brief   摄像头的构造函数.
 * 
 */
Camera::Camera()
{
	bOpened = false;
}

/**
 * \brief   摄像头析构函数.
 * 
 */
Camera::~Camera()
{
	if (!capture.isOpened())
	{
		capture.release();
	}
}

/**
 * \brief   打开摄像头.
 * 
 * \param index 摄像头编号
 * \return      true打开成功，false打开失败
 */
bool Camera::open(int index)
{

	 //capture(0);
#if 0
	if (capture.open(index, cv::CAP_DSHOW))
	{
		capture.set(cv::CAP_PROP_FRAME_WIDTH, 840);// 840
		capture.set(cv::CAP_PROP_FRAME_HEIGHT, 500); //500
		bOpened = true;
		return true;
	}
	else {
		bOpened = false;
		return false;
	}
#endif
	return true;
}

/**
 * \brief   关闭摄像头.
 * 
 */
void Camera::close()
{
	if (bOpened) {
		capture.release();
		bOpened = false;
	}

	return;
}

/**
 * \brief   读取摄像头frame数据.
 *
 * \return  读取的摄像头数据
 */
cv::Mat Camera::read()
{
	cv::Mat mat;
	//capture.read(mat);
	

	capture >> mat;
	return mat;
}